//
//  CJAsyncs.swift
//  CJPack
//
//  Created by 陈警卫 on 2023-08-24.
//

import UIKit
import Foundation

public struct CJAsyncs {
    
    /// 延时异步线程
    /// seconds延时时间
    /// execute异步执行
    /// mainExecute回主线程执行
    @discardableResult
    public func asyncDelay(_ seconds: Double, execute: @escaping (() -> Void), mainExecute: (() -> Void)? = nil) -> DispatchWorkItem {
        
        let item = DispatchWorkItem(block: execute)
        DispatchQueue.global().asyncAfter(deadline: DispatchTime.now() + seconds, execute: item)
        if let mainExecute = mainExecute {
            item.notify(queue: DispatchQueue.main, execute: mainExecute)
        }
        return item
    }
    
}
